package org.dey.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import org.dey.pojo.Member;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @author deyran
 * @classname
 * @see BaseMapper
 */
@Repository
public interface MemberReportMapper extends BaseMapper<Member> {


    @Select(" select count(id) from t_member where reg_time <= #{value}")
    public Integer getMemberCountByMonth(String m);

    @Select("select s.name,count(o.id) as value from  t_order o ,t_setmeal s where o.setmeal_id = s.id group by s.name")
    public List<Map<String, Object>> findSetmealCount();

    //今日新增会员数
    @Select("select count(id) from t_member where reg_Time <= #{value}")
    public Integer findMemberCountByDate(String today);

    //总会员数
    @Select("select count(id) from t_member")
    Integer findMemberTotalCount();

    //本周新增会员数、本月新增会员数
    @Select("select count(id) from t_member where reg_Time >= #{value}")
    Integer findMemberCountAfterDate(String thisWeekMonday);

    //今日预约数
    @Select("select count(id) from t_order where orderDate = #{value}")
    Integer findOrderCountByDate(String today);

    //本周预约数、本月预约数
    @Select("select count(id) from t_order where orderDate >= #{value}")
    Integer findOrderCountAfterDate(String thisWeekMonday);

    //今日到诊数
    @Select("select count(id) from t_order where orderDate = #{value} and orderStatus = '已到诊'")
    Integer findVisitsCountByDate(String today);

    //本周到诊数、本月到诊数
    @Select("select count(id) from t_order where orderDate >= #{value} and orderStatus = '已到诊'")
    Integer findVisitsCountAfterDate(String thisWeekMonday);

    //热门套餐（取前4）
    @Select("select s.name, count(o.id) setmeal_count , count(o.id)/(select count(id) from t_order) proportion " +
            "from t_order o inner join t_setmeal s on s.id = o.setmeal_id group by o.setmeal_id " +
            "order by setmeal_count desc limit 0,4")
    List<Map> findHotSetmeal();
}
